package com.example.server.mapper;

import com.example.server.entity.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Insert("INSERT INTO message(conversation_id, sender, content) " +
            "VALUES(#{conversation_id}, #{sender}, #{content})")
    int insertMessage(@Param("conversation_id") Integer conversation_id,
                      @Param("sender") String sender,
                      @Param("content") String content);

    @Select("SELECT * FROM message WHERE conversation_id = #{conversation_id} ORDER BY timestamp ASC")
    List<Message> selectMessagesByConversationId(Integer conversation_id);

    // Delete messages by conversation_id
    @Delete("DELETE FROM message WHERE conversation_id = #{conversation_id}")
    void deleteMessagesByConversationId(@Param("conversation_id") Integer conversation_id);
}
